#ifdef __C_LIST_H__
#define __C_LIST_H__
#include"cds_list.h"

#ifdef __cplusplus
extern "C" {
#endif


typedef struct clist_node{
    struct list_head entry;
    void * data;
}clist_node_t;

typedef struct clist{
    clist_node_t  head;
    int size;
} clist_t;

//初始化链表节点
#define CLIST_NODE_INIT( clist_node,data ) do{\
    (clist_node)->data = (data);\
    INIT_LIST_HEAD(&(clist_node)->entry);\
}while(0)

//初始化链表
#define CLIST_INIT(clist) do{\
    (clist)->size = 0; \
    CLIST_NODE_INIT( &(clist)->head,NULL );\
}while(0)

//添加数据(链表尾部添加)
void clist_add(clist_t * list, void * data);
//添加数据(头部添加)
void clist_add_head(clist_t * list, void * data);
//删除数据(头部删除)
void * clist_del_first(clist_t * list);
//删除数据(尾部删除)
void * clist_del_last(clist_t * list);

//获取链表中的数据量
static inline int clist_size(clist_t * list){
   return list->size; 
}

//判断链表是否为空
static inline int clist_is_empty(clist_t * list ){
    return list_is_empty(&list->head.entry);
}

//清空链表
static inline void clist_clear(clist_t * list){
    list_clear(&list->head.entry);
}


#ifdef __cplusplus
}
#endif

#endif __C_LIST_H__
